/**
 * 将项目按文件名排序
 */

const vscode = require('vscode');
const util = require('../util');
const path = require('path');
const fs = require('fs-extra');

module.exports = function(context) {
    context.subscriptions.push(vscode.commands.registerCommand('extension.oepnFinanceFiles', function () {
        vscode.window.showInputBox({
            prompt: '请粘贴金融特有的路由字符串到这里以便快速打开文件：',
            placeHolder: '形如：http_loan_additional_doBindBankCard',
        }).then(input => {
            input = input || 'http_loan_additional_doBindBankCard';
            const temp = input.split('_');
            const methodName = temp.pop();
            const project = util.getProjectPath();
            const fileName = path.resolve(project, `./app/service/${temp.join('/')}.js`);
            if (fs.existsSync(fileName)) {
                util.openFileInVscode(fileName, methodName);
            } else {
                util.showError(`未找到文件：${fileName}`);
            }
        });
    }));
};